﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NotAClue.Web
{
    public static class TypeExtensions
    {
        public static bool Implements(this Type type, Type interfaceType)
        {
            Func<Type, bool> typeMatcher = t => interfaceType.IsAssignableFrom(t);
            if (interfaceType.IsGenericType)
            {
                typeMatcher = t => t.IsGenericType && interfaceType.IsAssignableFrom(t.GetGenericTypeDefinition());
            }
            return typeMatcher(type) || type.GetInterfaces().Any(typeMatcher);
        }
    }
}